package com.bitoon.basketdudes.web;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

public class Logout extends BaseActionServletAware {

    private String urlRedirect = "";

    public String getUrl() {
        return urlRedirect;
    }

    @Override
    public String execute() {
        //Map<String,Object> session = ActionContext.getContext().getSession();
        session.put("bd_userId", "0");
        session.put("bd_userLogado", null);
        session.remove("mensajesLeidos");
        ValueStack valueStack = ActionContext.getContext().getValueStack();
        valueStack.set("stackUserId", null);
        valueStack.set("stackUserLogado", null);

        HttpServletResponse response = getServletResponse();
        Cookie reminder = new Cookie("bdrc", null); // bdrc => BasketDudes Reminder Cookie
        reminder.setMaxAge(0);
        response.addCookie(reminder);
        
        //urlRedirect = (String)session.get("paginaRetornoAnt");
        urlRedirect = (String)session.get("paginaRetorno");
        if (urlRedirect==null) {
            urlRedirect="/";
        } else if (urlRedirect.equals("/home")) {
            urlRedirect="/";
        }

        return REDIRECT;
    }

}
